package com.hotel.reservation.controller.before;

import com.hotel.reservation.po.ReservePo;
import com.hotel.reservation.po.RoomPo;
import com.hotel.reservation.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 0.1
 * @Author: oliver chen
 * @Description: 前台客房
 * @Date:Create：in 2021/7/31 11:51
 * @Modified By：
 */
@Controller
@RequestMapping("/before/room")
public class BeforeRoomController {
    @Autowired
    private RoomService roomService;

    @RequestMapping("/selectByRoomType")
    public List<RoomPo> selectByRoomType(String roomType,Model model){
        List<RoomPo> list = roomService.selectByRoomType(roomType);
        model.addAttribute("rooms",list);
        return list;
    }
    @RequestMapping("/selectByRoomState")
    public List<RoomPo> selectByRoomState(int roomState,Model model){
        List<RoomPo> roomPos = roomService.selectByRoomState(roomState);
        model.addAttribute("rooms",roomPos);
        return roomPos;
    }

    @RequestMapping("/selectEnableRooms")
    public String selectEnableRooms(String roomType,Model model,int userId){
        List<RoomPo> roomPos = roomService.selectEnableRooms(0,roomType);
        List<String> roomIds = new ArrayList<>();
        for (RoomPo roomPo : roomPos){
            roomIds.add(roomPo.getRoomId());
        }
        model.addAttribute("roomType",roomType);
        model.addAttribute("enableRooms",roomPos);
        model.addAttribute("roomIds",roomIds);
        ReservePo reservePo = new ReservePo();
        model.addAttribute("reserve",reservePo);
        model.addAttribute("userId",userId);
        return "before/reserve";
    }
}
